<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>渲染器-内置数字渲染器辅助函数</title>
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"></link>
</head>
<body>
<table id="example" class="display" style="width:100%">
    <thead>
        <tr>
            <th>产品名称</th>
            <th>创建人</th>
            <th>创建时间</th>
            <th>价格</th>
            <th>成本</th>
        </tr>
    </thead>
    <tbody>
        
    </tbody>
</table>

<script>

    let data = [
            {
                "product": "Toy car",
                "creator": {
                    "firstName": "Fiona",
                    "lastName": "White"
                },
                "created": "2015-11-01",
                "price": 19.99,
                "cost": 12.53
            },
            {
                "product": "Train",
                "creator": {
                    "firstName": "Keith",
                    "lastName": "Shan"
                },
                "created": "2020-07-20",
                "price": 399999999.99,
                "cost": 0.01
            }
    ];
    $(document).ready(function () {
        $('#example').DataTable({
            data:data,
            columns:[
                {data:"product"},
                {data:"creator.firstName"},
                {data:"created"},
                {
                    data:"price",
                    render:$.fn.dataTable.render.number( ',', '.', 5, '￥','元' )
                },
                {data:"cost"}
            ]
        });
    });
</script>
</body>
</html>